home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form frmSprite
- BorderStyle = 1 'Fixed Single
- Caption = "The Sprite Program"
- ClientHeight = 5460
- ClientLeft = 1215
- ClientTop = 1530
- ClientWidth = 6075
- Height = 6150
- Icon = "SPRITE.frx":0000
- Left = 1155
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 364
- ScaleMode = 3 'Pixel
- ScaleWidth = 405
- Top = 900
- Width = 6195
- Begin VB.Timer Timer1
- Interval = 50
- Left = 2760
- Top = 720
- End
- Begin TegommLibCtl.Tegomm Tegomm1
- Height = 495
- Left = 1320
- TabIndex = 0
- Top = 120
- Width = 3510
- _version = 65536
- _extentx = 6191
- _extenty = 873
- _stockprops = 64
- End
- Begin TegsprLibCtl.TegoSprite sprMan
- Left = 2160
- Top = 2040
- _version = 65536
- _extentx = 1296
- _extenty = 1931
- _stockprops = 0
- spritefilename = "C:\OCXPROG\PROGRAMS\CH05\MAN0.BMP"
- maskfilename = "C:\OCXPROG\PROGRAMS\CH05\MMAN0.BMP"
- spriteleft = 144
- spritetop = 136
- spriteheight = 73
- spritewidth = 49
- End
- Begin TegsprLibCtl.TegoSprite sprBack
- Left = 0
- Top = 0
- _version = 65536
- _extentx = 10716
- _extenty = 9710
- _stockprops = 0
- spritefilename = "C:\OCXPROG\PROGRAMS\CH05\BGND.BMP"
- maskfilename = "C:\OCXPROG\PROGRAMS\CH05\MBGND.BMP"
- spriteheight = 367
- spritewidth = 405
- transparent = 0 'False
- autosize = -1 'True
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuExit
- Caption = "E&xit"
- End
- End
- Begin VB.Menu mnuHelp
- Caption = "&Help"
- Begin VB.Menu mnuAbout
- Caption = "&About..."
- End
- End
- Attribute VB_Name = "frmSprite"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- ' All variables must be declared.
- Option Explicit
- ' Declare handles for the show's sprites.
- Dim gBack As Long
- Dim gMan0 As Long
- Dim gMan1 As Long
- Dim gMan2 As Long
- Dim gMan3 As Long
- Private Sub Form_Load()
- Dim Path
- ' Get the name of the directory where the
- ' program resides.
- Path = App.Path
- If Right(Path, 1) <> "\" Then
- Path = Path + "\"
- End If
- ' Open a WAV file for background music.
- Tegomm1.Visible = False
- Tegomm1.DeviceType = "WaveAudio"
- Tegomm1.filename = Path + "LASTC2M6.WAV"
- Tegomm1.Command = "Open"
- ' Start playing the WAV file.
- Tegomm1.Command = "Play"
- ' Initialize all the sprite controls.
- sprBack.InitializeSprite Me.hWnd
- sprMan.InitializeSprite Me.hWnd
-
- ' Open all the sprites that will be used in our show.
- gMan0 = sprBack.OpenSprite(Path + "man0.bmp")
- gMan1 = sprBack.OpenSprite(Path + "man1.bmp")
- gMan2 = sprBack.OpenSprite(Path + "man2.bmp")
- gMan3 = sprBack.OpenSprite(Path + "man3.bmp")
- gBack = sprBack.OpenSprite(Path + "bgnd.bmp")
- End Sub
- Private Sub Form_Paint()
- ' Draw the sprBack sprite inside WinG
- sprBack.SpriteHandle = gBack
- sprBack.DrawSprite
- ' Draw the sprMan sprite inside WinG.
- sprMan.SpriteHandle = gMan0
- sprMan.DrawSprite
- ' Slam WinG into the screen
- sprBack.SlamIt
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- ' Free all the sprites of the show.
- sprBack.CloseSprite (gBack)
- sprBack.CloseSprite (gMan0)
- sprBack.CloseSprite (gMan1)
- sprBack.CloseSprite (gMan2)
- sprBack.CloseSprite (gMan3)
- End Sub
- Private Sub mnuAbout_Click()
- Dim Title
- Dim Msg
- Dim CR
- CR = Chr(13) + Chr(10)
- ' Prepare the title of the About message box.
- Title = "About the Sprite Program"
- Msg = "This program was written with Visual "
- Msg = Msg + "Basic for Windows, using the "
- Msg = Msg + "TegoSoft Sprite OCX control. "
- Msg = Msg + CR + CR
- Msg = Msg + "The TegoSoft Sprite OCX control "
- Msg = Msg + "is part of the TegoSoft OCX Control "
- Msg = Msg + "Kit - a collection of various OCX controls. "
- Msg = Msg + CR + CR
- Msg = Msg + "For more information about the "
- Msg = Msg + "TegoSoft OCX Control Kit, contact TegoSoft "
- Msg = Msg + "at:"
- Msg = Msg + CR + CR
- Msg = Msg + "TegoSoft Inc." + CR
- Msg = Msg + "P.O. Box 389" + CR
- Msg = Msg + "Bellmore, NY 11710"
- Msg = Msg + CR + CR
- Msg = Msg + "Phone: (516)783-4824"
- ' Display the About message box.
- MsgBox Msg, vbInformation, Title
- ' Make sure that there is playback after
- ' the user closes the modal message box.
- Tegomm1.Command = "Play"
- End Sub
- Private Sub mnuExit_Click()
- ' Terminate the program.
- Unload Me
- End Sub
- Private Sub Tegomm1_Done()
- ' If playback reached the end of the WAV file,
- ' rewind the WAV file and play again.
- If Tegomm1.Position = Tegomm1.Length Then
- Tegomm1.Command = "Prev"
- Tegomm1.Command = "Play"
- End If
- End Sub
- Private Sub Timer1_Timer()
- Static WalkingDirection
- Dim ManLeft, ManTop, ManWidth, ManHeight
- ' If the program's window is currently minimized,
- ' exit this procedure.
- If Me.WindowState = 1 Then
- Exit Sub
- End If
- ' Draw the section of the background where the
- ' Man sprite is located.
- ManLeft = sprMan.SpriteLeft
- ManTop = sprMan.SpriteTop
- ManWidth = sprMan.SpriteWidth
- ManHeight = sprMan.SpriteHeight
- sprBack.SpriteHandle = gBack
- sprBack.PartialDraw ManLeft, ManTop, ManWidth, ManHeight
-
- ' The following If-ElseIf statements, animate
- ' the sprMan sprite control. The man is moving
- ' inside a room in four directions:
- ' Direction 0 - Towards the user next to the left
- ' wall of the room.
- ' Direction 1 - From the left side of the room to
- ' the right side of the room.
- ' Direction 2 - Away from the user next to the
- ' right wall of the room.
- ' Direction 3 - From the right side of the room
- ' to the left side of the room.
- ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- ' x <----------------------- x
- ' x | Direction 3 x
- ' x | /|\ x
- ' x | | x
- ' x |Direction Direction| x
- ' x | 0 2 | x
- ' x | | x
- ' x | | x
- ' x \|/ Direction 1 x
- ' x -------------------------> x
- ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- If WalkingDirection = 0 Then
- ' Show the man going in direction 0.
- sprMan.StretchBottom 10
- sprMan.StretchLeft 5
- sprMan.SpriteHandle = gMan0
- sprMan.DrawSprite
- If sprMan.SpriteHeight >= 210 Then
- WalkingDirection = 1
- End If
- ElseIf WalkingDirection = 1 Then
- ' Show the man going in direction 1.
- sprMan.SpriteLeft = sprMan.SpriteLeft + 6
- sprMan.SpriteHandle = gMan1
- sprMan.DrawSprite
- If sprMan.SpriteLeft >= 220 Then
- WalkingDirection = 2
- End If
- ElseIf WalkingDirection = 2 Then
- ' Show the man going in direction 2.
- sprMan.StretchBottom -10
- sprMan.StretchRight -5
- sprMan.SpriteHandle = gMan2
- sprMan.DrawSprite
- If sprMan.SpriteHeight <= 80 Then
- WalkingDirection = 3
- End If
- ElseIf WalkingDirection = 3 Then
- ' Show the man going in direction 3.
- sprMan.SpriteLeft = sprMan.SpriteLeft - 6
- sprMan.SpriteHandle = gMan3
- sprMan.DrawSprite
- If sprMan.SpriteLeft <= 150 Then
- WalkingDirection = 0
- End If
- End If
- ' Slam WinG into the screen.
- sprBack.SlamIt
- End Sub
-